import random
import datetime


class BankAccount:
    """银行账户类"""

    def __init__(self, account_holder, initial_balance=0):
        self.account_number = self._generate_account_number()
        self.account_holder = account_holder
        self.balance = initial_balance
        self.transaction_history = []
        self.creation_date = datetime.datetime.now()

    def _generate_account_number(self):
        """生成10位随机账户号码"""
        return ''.join([str(random.randint(0, 9)) for _ in range(10)])

    def deposit(self, amount):
        """存款"""
        if amount <= 0:
            return False, "存款金额必须大于0"

        self.balance += amount
        self.transaction_history.append(
            f"{datetime.datetime.now()}: 存款 ${amount:.2f}"
        )
        return True, f"存款成功! 当前余额: ${self.balance:.2f}"

    def withdraw(self, amount):
        """取款"""
        if amount <= 0:
            return False, "取款金额必须大于0"

        if amount > self.balance:
            return False, "余额不足"

        self.balance -= amount
        self.transaction_history.append(
            f"{datetime.datetime.now()}: 取款 ${amount:.2f}"
        )
        return True, f"取款成功! 当前余额: ${self.balance:.2f}"

    def transfer(self, amount, target_account):
        """转账到目标账户"""
        if amount <= 0:
            return False, "转账金额必须大于0"

        if amount > self.balance:
            return False, "余额不足，无法转账"

        self.balance -= amount
        target_account.balance += amount

        # 记录交易历史
        self.transaction_history.append(
            f"{datetime.datetime.now()}: 转账 ${amount:.2f} 到账户 {target_account.account_number}"
        )
        target_account.transaction_history.append(
            f"{datetime.datetime.now()}: 收到来自账户 {self.account_number} 的转账 ${amount:.2f}"
        )

        return True, f"转账成功! 当前余额: ${self.balance:.2f}"

    def get_balance(self):
        """获取余额"""
        return self.balance

    def get_transaction_history(self):
        """获取交易历史"""
        return self.transaction_history

    def get_account_info(self):
        """获取账户信息"""
        return {
            "账户号码": self.account_number,